/*
 * Filename    : Utils.java
 * Projectname : RamaShinta
 * Date        : Nov 17, 2012 , 12:11:30 PM 
 * 
 * @author Pratama Nur Wijaya
 */

package com.amikomgamedev.ramashinta;

import java.util.Random;

import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.sprite.TiledSprite;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.util.debug.Debug;

import com.amikomgamedev.ramashinta.game.Game_Config;
import com.amikomgamedev.ramashinta.game.Game_Data;
import com.amikomgamedev.ramashinta.game.Game_Define;

public class Utils implements Game_Data, Game_Define
{
	private static boolean	cheat	= true;

	public static boolean isCheat()
	{
		return cheat;
	}

	public static float getRatio(float nil)
	{
		float nil_Ratio = 0;

		switch (Game_Config.RATIO_USE)
		{
			case RATIO_WIDTH:
				nil_Ratio = nil / RATIO_RES_WIDTH * RES_WIDTH;
				break;
			case RATIO_HEIGHT:
				nil_Ratio = nil / RATIO_RES_HEIGHT * RES_HEIGHT;
				break;
		}

		return nil_Ratio;
	}

	public static float getRatioW(float nil)
	{
		return nil / RATIO_RES_WIDTH * RES_WIDTH;
	}

	public static float getRatioH(float nil)
	{
		return nil / RATIO_RES_HEIGHT * RES_HEIGHT;
	}

	public static void TRACE(String arg)
	{
		if (Game_Config.TRACE)
		{
			System.out.println(arg);
		}
	}

	public static void DEBUG(Exception arg)
	{
		if (Game_Config.DEBUG)
		{
			Debug.e(arg);
		}
	}

	public static TextureOptions getTextureOption()
	{
		return Game_Config.AA_ENABLE ? TextureOptions.REPEATING_BILINEAR : TextureOptions.REPEATING_NEAREST;
	}

	public static int GetRandomInRange(int begin, int end)
	{
		if (begin > end)
		{
			System.out.println("end number shouldn't bigger that the beginning number");
			return -1;
		}
		Random randomGenerator = new Random();
		int range = end - begin;
		if (!(begin <= begin + (randomGenerator.nextInt(range + 1)) && end >= begin
				+ (randomGenerator.nextInt(range + 1))))
		{
			System.out.println("there is are errors on this method , please double check and report!");
		}
		return begin + (randomGenerator.nextInt(range + 1));
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			Sprite spr_Icon_Stage)
	{		
		return isOnArea(
				p_X,
				p_Y,
				spr_Icon_Stage.getX(),
				spr_Icon_Stage.getX() + spr_Icon_Stage.getWidth(),
				spr_Icon_Stage.getY(),
				spr_Icon_Stage.getY() + spr_Icon_Stage.getHeight());
	}
	
	public static boolean isOnArea(
			float p_X,
			float p_Y,
			float p_MinX,
			float p_MaxX,
			float p_MinY,
			float p_MaxY)
	{
		if(p_X > p_MinX
				&& p_X < p_MaxX
				&& p_Y > p_MinY
				&& p_Y < p_MaxY)
			return true;
		
		return false;
	}

}
